package nl.boelen.game.level.tile;


public class AnimatedTile extends BasicTile {

    private int[][] animationCoords;
    private int currentAnimationIndex;
    private long lastIterationTime;
    private int animationMilliSecDelay;

    public AnimatedTile(int id, int[][] animationCoords, int tileColor, int indexColor, int animationMilliSecDelay) {
        super(id, animationCoords[0][0], animationCoords[0][1], tileColor, indexColor);
        this.animationCoords = animationCoords;
        this.currentAnimationIndex = 0;
        this.lastIterationTime = System.currentTimeMillis();
        this.animationMilliSecDelay = animationMilliSecDelay;
    }

    public void tick() {
        if ((System.currentTimeMillis() - lastIterationTime) >= animationMilliSecDelay) {
            lastIterationTime = System.currentTimeMillis();
            currentAnimationIndex = (currentAnimationIndex + 1) % animationCoords.length;
            this.tileId = (animationCoords[currentAnimationIndex][0] + animationCoords[currentAnimationIndex][1] * 32);
        }
    }
}
